/**
 * Created by Administrator on 2017/1/7.
 */
var should = require('should');
var fs = require('fs');

suite('fs-readdir-or-file-unit-tests', function () {
    var demoDir = 'D:\\Projects\\CSharp Projects\\Demo';
    var demoFile = 'D:\\Projects\\CSharp Projects\\Demo\\Demo.sln';
    var expectedFiles = [
        'AjaxServerControlDemo',
        'ConsoleApplicationDemo',
        'Demo.sln',
        'Demo.suo',
        'Demo.v11.suo',
        'Demo.v12.suo',
        'packages',
        'ServerControlDemo',
        'TestResults',
        'UnitTestProjectDemo',
        'VisualBasicConsoleApplicationDemo',
        'WcfServiceLibraryDemo',
        'WebApplicationDemo',
        'WindowsFormsApplicationDemo',
        'WpfApplicationDemo'
    ];
    var demoSlnData = 'Microsoft';

    test('.readdir(path, callback)', function (done) {
        fs.readdir(demoDir, function (err, files) {
            should.ifError(err);
            should.deepEqual(files, expectedFiles);
            done();
        })
    });

    test('.readdirSync(path)', function () {
        var files = fs.readdirSync(demoDir);
        should.deepEqual(files, expectedFiles);
    });

    test('.readFile(file, options, callback)', function (done) {
        fs.readFile(demoFile, 'utf-8', function (err, data) {
            should.ifError(err);
            should.deepEqual(data.slice(3, 12), demoSlnData);
            done();
        })
    });

    test('.readFileSync(file,options)', function () {
        var data = fs.readFileSync(demoFile, 'utf-8');
        should.deepEqual(data.slice(3, 12), demoSlnData);
    })
});